import { request } from '@/utils/request';
import type { EmployeeListResult, EmployeeRequest, EmployeeUpdateRequest } from './model/employeeModel';
const Api = {
  EmployeeList: 'manage/employee/list',
  EmployeeDetail: 'manage/employee',
  EmployeeUpdate: 'manage/employee',
  EmployeeExport: 'manage/employee/export',
  EmployeeUpdateRole: 'manage/employee/updateRole',
  EmployeeEnableOrDisable: 'manage/employee/enableOrDisable',
};

/**
 * 获取员工列表
 * @param params
 * @returns
 */
export function getEmployeeList(params: EmployeeRequest) {
  return request.post<EmployeeListResult>({
    url: Api.EmployeeList,
    params,
  });
}

/**
 * 获取员工详情
 * @param id
 * @returns
 */
export function getEmployeeDetail(id: number) {
  return request.get({
    url: `${Api.EmployeeDetail}/${id}`,
  });
}

/**
 * 更新员工信息
 * @param data
 * @returns
 */
export function updateEmployee(data: EmployeeUpdateRequest) {
  return request.put({
    url: Api.EmployeeUpdate,
    data,
  });
}

/**
 * 启用或禁用员工
 * @param data
 * @returns
 */
export function enableOrDisableEmployee(data: EmployeeUpdateRequest) {
  return request.put({
    url: Api.EmployeeEnableOrDisable,
    data,
  });
}

/**
 * 导出员工信息
 * @param pageNum
 * @returns
 */
export function exportEmployee(pageNum: number, pageSize: number) {
  return request.get({
    url: Api.EmployeeExport,
    params: {
      pageNum,
      pageSize,
    },
    responseType: 'blob',
  });
}

/**
 * 更新员工角色
 * @param data
 * @returns
 */
export function updateEmployeeRole(data: EmployeeUpdateRequest) {
  return request.put({
    url: Api.EmployeeUpdateRole,
    data,
  });
}
